package org.tysite.tyservice.example.jsonview.dto.serializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import org.tysite.tyservice.example.jsonview.dto.JsonViewTypeDTO;

import java.io.IOException;

/**
 * JsonViewTypeDTO 的JsonView序列化类
 * @author tysite
 * @date 2020/4/1 0001
 */
public class JsonViewTypeSerializer extends JsonSerializer<JsonViewTypeDTO> {
    
    @Override
    public void serialize(JsonViewTypeDTO value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
        gen.writeStartObject();
        gen.writeNumberField("id", value.getId());
        gen.writeStringField("name", value.getName());
        gen.writeEndObject();
    }
    
}